<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 编写一个函数，排列任意元素个数的数字数组，按从小到大的顺序输出 -->
    <script>
      var list = [81, 132, 24, 51, 1, 6];
      // 数组sort方法实现
      function sort1(array) {
        array.sort(function (a, b) {
          return a - b;
        });
        return array;
      }
      console.log(sort1(list));

      // 原生js逻辑实现
      function sort2(array) {
        for (i = 0; i < array.length - 1; i++) {
          for (j = 0; j < array.length - 1 - i; j++) {
            if (array[j] > array[j + 1]) {
              var a = array[j];
              array[j] = array[j + 1];
              array[j + 1] = a;
            }
          }
        }
        return array;
      }
      console.log(sort2(list));
    </script>
  </body>
</html>
